/*
 * $Id: MemoryPoolable.h,v 1.4 2005-07-13 14:52:45 bacon Exp $
 */

#ifndef _XPP_BAS_MEMORYPOOLABLE_CLASS_
#define _XPP_BAS_MEMORYPOOLABLE_CLASS_

#include <xp/types.h>
#include <xp/macros.h>
#include <xpp/bas/MemoryPool.h>

// some compilers doesn't allow to change size_t 
// to xp_size_t for operator new.
#include <stddef.h> 

namespace xpp
{
	namespace bas
	{

		class MemoryPoolable
		{
		public:
			inline void* operator new (size_t size)
			{
				return ::operator new (size);
			}

			inline void operator delete (void* ptr)
			{
				::operator delete (ptr);
			}

			inline void* operator new (size_t /*size*/, MemoryPool* mp)
			{
				return mp->allocate ();
			}

//#if defined(__BORLANDC__) 
			inline void dispose (void* ptr, MemoryPool* mp)
			{
				mp->dispose (ptr);
			}
//#else
//			void operator delete (void* ptr, MemoryPool* mp)
//			{
//				mp->dispose (ptr);
//			}
//#endif

		};
	}
}

#endif
